type IMethods = {
	[key: string]: (...args: any) => any;
};

const wrap = (path: string, cb: (data: any, ...args: any[]) => boolean) => {
	return function (data: any) {
		const res = cb && cb(data);
	};
};

const validatorMethods: IMethods = {
	// 不能为空
	notNull: (data) => {
		return data !== null && data !== undefined;
	},

	// 用户名
	userName: (data): boolean => {
		return /^[a-zA-Z0-9_-]{4,16}$/.test(data);
	},

	// 密码
	password: (data: any): boolean => {
		return /[A-Za-z\d\W_]{6,20}/.test(data);
	},

	// 中文名称
	cnName: (data: any): boolean => {
		return /^[\u4e00-\u9fa5]{2,12}$/.test(data);
	},

	// 座机电话
	tel: (data: any): boolean => {
		return /^\d{3}-\d{7,8}|\d{4}-\d{7,8}$/.test(data);
	},

	// 11位手机电话
	phone: (data: any): boolean => {
		return /^\d{1}\d{10}$/.test(data);
	},

	// 日期
	date: (data: any): boolean => {
		return /^\d{4}-\d{1,2}-\d{1,2}$/.test(data);
	},

	// 邮箱
	email: (data: any): boolean => {
		return /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(
			data,
		);
	},

	// 身份证号
	pi: (data: any): boolean => {
		return /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(
			data,
		);
	},

	// ip
	ip: (data: any): boolean => {
		return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
			data,
		);
	},

	// 布尔
	boolean: (data: any): boolean => {
		return typeof data === 'boolean';
	},

	// 颜色十六进制
	colorHex: (data: any): boolean => {
		return /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(data);
	},

	// 最小长度
	minLength: (data: any, [_, min] = []): boolean => {
		return data.length >= min;
	},

	// 最小长度
	maxLength: (data: any, [_, max] = []): boolean => {
		return data.length <= max;
	},

	// 长度范围
	rangeLength: (data: any, [_, min, max]) => {
		return data.length >= min && data.length <= max;
	},

	// 最小值
	min: (data: any, [_, min]) => {
		return data > min;
	},

	// 最大值
	max: (data: any, { max }): boolean => {
		return Number(data) <= max;
	},

	// 整数
	intNumber: (data: any) => {
		return typeof data === 'number' && data % 1 === 0;
	},

	// 浮点数
	floatNumber: (data: any) => {
		return typeof data === 'number' && data % 1 !== 0;
	},

	// 负数
	minusNumber: (data: any) => {
		return typeof data === 'number' && data < 0;
	},

	// 数字范围
	rangeNumber: (data: any, [_, min, max]) => {
		return typeof data === 'number' && data >= min && data <= max;
	},

	// 包含某一个
	include: (data: any, [_, types]) => {
		return types.includes(data);
	},
};

export { validatorMethods };
